//
//  AppDelegate.m
//  01-UIView、UIWindow
//
//  Created by QC.L on 16/7/14.
//  Copyright © 2016年 QC.L. All rights reserved.
//

#import "AppDelegate.h"
#import "UIView+Frame.h"
@interface AppDelegate ()<UITextFieldDelegate>

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.

    // 程序的组成结构
    //1.main.m 主要实现了程序的正常运行
    //2.AppDelegate 程序的执行者，签订了UIAppliacationDelegate（协议方法可选）
    //注意：APPDelegate就是也普通的类，只不过签订了协议，才有了这么多方法
    //3.ViewController，视图控制器 主要负责视图管理，看得见，摸得到
    //4.main.sb（负责视图管理） LauchScreen.sb（负责启动页） 可视化管理 （Xcode7以前 LaunchScreen，xib）
    //5.Assets.xcassets 主要用来管理图片素材 （Xcode7 以前叫images.xcassets）
    //6.info.plist （工程配置文件）
    
    
    //模拟器
    //command + 1~5 改变模拟器大小
    //command +左/右，横竖屏切换
    
    //iOS概述
    //iOS 错误的写法：IOS ios Ios IoS
    
    //1.UIWindow （程序中，只有一个主window）
    // 1>取消程序的可视化入口，Main.sb
    // 2>创建主window对象
    //创建主 window，使其大小和屏幕一样
    //UIScreen 系统屏幕类
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    //给你创建的窗口填颜色 UIcolor 系统的颜色类
    _window.backgroundColor =[UIColor blueColor];
    //让window 显示，并成为主窗口 并 显示
    [_window makeKeyAndVisible];
    //4.设置window主窗口
    //在xcode7 之后 必须设置rootViewController，否则，在该方法结束的时候，会崩溃
    _window.rootViewController = [[UIViewController alloc]init];
    /*
    
    // 3>UIwindow 继承于UIView
    
    // 2.UIView （与NSObject相似，是UI阶段的根类，大部分控件继承与UIView）
    // 学习新类
    // 1>需要新类包含哪些初始方法
    // 2>方法和属性
    // 3>
    //
    //
    //创建UIView
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    //添加背景色
    view.backgroundColor = [UIColor greenColor];
    //直接加到_WINDOWS 上
    [_window addSubview:view];
    //遇到UIView的子类，都看完一使用以上方式创建和显示
    // UIView在屏幕中显示为矩形
    
    //iOS系统坐标系
    //1.与数学中的坐标系不同 ，y轴的正方向是向下的
    //2.原点是屏幕的左上角
    
    // frame bounds center(UIView的属性)
    // 1.frame (x,y,width,heigh) 试图在其父视图上的位置
    // 2.bounds (x,y,width,heigh) 自己视图本身的坐标系(0,0,width,heigh)
    // 3.center 中心点
//       view.center = CGPointMake(50, 50);
//     bounds 对视图的影响测试
    //bounds的 x，y影响子视图的frame，改变坐标系
    //CGRect 和CGPoint
    view.frame = CGRectMake(0, 0, 80, 80);
    NSLog(@"改变bounds前%@",NSStringFromCGRect(view.frame) );
    NSLog(@"改变center前的%@",NSStringFromCGPoint(view.center));
    view.bounds = CGRectMake(0, 0, 80, 80);
    NSLog(@"改变bounds后%@",NSStringFromCGRect(view.frame) );
    NSLog(@"改变center后的%@",NSStringFromCGPoint(view.center));
//    bounds 的x，y影响子视图的果然么，改变坐标系
    UIView *subView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 60)];
    subView.backgroundColor = [UIColor greenColor];
    [view addSubview:subView];
    
    //改变绿色view的大小，width变成100
    view.frame = CGRectMake(view.frame.origin.x, view.frame.origin.y,100,view.frame.size.height);
    // view.frame get方法
    // frame.size 结构体
    // OC和C的内容结合，是一个常量
    //view.frame.size.width = 100;
        CGRect rect = view.frame;
        rect.size.width = 100;
        view.frame = rect;
    
    view.hl_width = 100;
*/
    //UIView的基本属性
    UIView *testView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    [_window addSubview:testView];
    //背景色
    testView.backgroundColor = [UIColor cyanColor];
    //alpha 透明度0。0~1.0 默认值 1.0
    testView.alpha = 0.2;
   //3.tag 标记（编号）(默认为0)
    testView.tag = 1000;
    //根据tag获取到对应的view
    UIView *view1 = [_window viewWithTag:1000];
//4.subViews
    UIView *arrayView = [ _window.subviews objectAtIndex:0];
    NSLog(@"%@",arrayView);
    //5.superView 父视图
    //testView.superview;
//    testView.superview;
  //6.hidden 隐藏和显示 YES/NO
    testView.hidden = YES;
    
    
    // 视图层级
    UIView *firstView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 80, 80)];
    firstView.backgroundColor = [UIColor orangeColor];
    UIView *secondView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 80, 80)];
    secondView.backgroundColor = [UIColor redColor];
    UIView *lastView = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 80, 80)];
    lastView.backgroundColor = [UIColor blackColor];
    //addSubview(添加视图)
    [_window addSubview:firstView];
    //insterSubview:atIndex(插入视图，到指定下标)
    NSLog(@"%@",_window.subviews);
    [_window insertSubview:secondView atIndex:2];
    //insterSubview:aboveSubview(插入视图，到指定视图的上面)
    [_window insertSubview:lastView aboveSubview:firstView];
    //insterSubview:belowSubview（插入视图，到指定视图的下面）
    [_window insertSubview:lastView belowSubview:secondView];
    
    // UILable (负责显示文本的)
    //如果没有自己的初始化方法，则使用父类的
    UILabel *lable = [[UILabel alloc] initWithFrame:CGRectMake(20, 100, 300, 100)];
    lable.backgroundColor = [UIColor yellowColor];
    [_window addSubview:lable];
    // lable的属性
    // 1.text
    lable.text = @"我叫王煌，我很热；看能否兼顾和欧文哦啊；的看来是你发几个户外；日历卡价格和锐拼接开关后唯品；人均国内宏观；";
    // 2.textColor 文本颜色
    lable.textColor = [UIColor lightGrayColor];
    //3.font 默认值 17
    lable.font = [UIFont systemFontOfSize:40];
    lable.font = [UIFont boldSystemFontOfSize:40];
    //4.textAlignment 对齐方式 默认对齐方式NSTextAlignmentLeft
    lable.textAlignment = NSTextAlignmentRight;
    //5.numberOfLines
    //不确定行数时，给0
    lable.numberOfLines = 0;
    //6.换行模式，。。。位置 lineBreakMode
    lable.lineBreakMode = NSLineBreakByCharWrapping;
    //7.阴影颜色
    lable.shadowColor = [UIColor redColor];
    lable.shadowOffset = CGSizeMake(2, 4);
    //UIButton (用来点击的)
    //UIButtonTypeSystem系统按钮类型
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.backgroundColor = [UIColor purpleColor];
    [_window addSubview:button];
    button.hl_x = 150;
    button.hl_y = 300;
    button.hl_height = 100;
    button.hl_width = 100;
    [_window addSubview:button];
    //给Button添加事件
    [button addTarget:self action:@selector(buttonClicked) forControlEvents:UIControlEventTouchUpInside];
    //给button添加文字
    [button setTitle:@"你点我啊~" forState:UIControlStateNormal];
    
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    //UITextField
    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(150, 450, 100, 100)];
    textField.backgroundColor = [UIColor yellowColor];
    [_window addSubview:textField];
    //1.给输入框附了初值
    textField.text = @"文字";
    //2.text.Color 文字颜色
    textField.textColor = [UIColor blackColor];
    // 3.borderStyle 边缘样式
    //UITextBorderStyleNone 无
    //UITextBorderStyleLine 有边缘线
    //UITextBorderStyleBezel
    //UITextBorderStyleRoundedRect 边缘圆角
    textField.borderStyle = UITextBorderStyleLine;

    //4.placeholder 占位字符
    //当text、不为空时，placeholder 是不显示的
    textField.placeholder = @"请输入你的爱好";
    
    //5.clearsOnBeginEdtting
    //
    //
    textField.clearsOnBeginEditing = YES;
    //command + K 显示、收起键盘

    textField.delegate = self;
    
    
    
    return YES;
}
- (void)buttonClicked {
    //结束编辑
    [_window endEditing:YES];
    NSLog(@"我被点了");
}
//开始编辑前
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    //return YES 可以编辑
    //return NO 不可以编辑
    return YES;
}
//已经开始编辑
- (void)textFieldDidBeginEditing:(UITextField *)textField {
    
}
- (void)textFieldDidEndEditing:(UITextField *)textField {
    
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    //处理点击return的时候，需要进行的操作
    //回收键盘
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
